﻿using Lhz.Common.Business;
using Lhz.Sc.Entity.Database;
using System;
using System.Linq;

namespace Lhz.Sc.Business
{
    public class UserProxy : EntityProxy<Guid, User>
    {
        public UserProxy(string pathConfiguration = null) : base(pathConfiguration)
        {

        }

        public User QueryByUsername(string username)
        {
            var query = CreateQueryable().QueryByUsername(username).ToList();
            if (query.Count > 1)
            {
                throw new ApplicationException("用户名【" + username + "】出现多次。");
            }
            else
            {
                return query.FirstOrDefault();
            }
        }

        public User QueryByUsernameAndPassword(string username, string password)
        {
            var user = QueryByUsername(username);
            if (user == null || user.Password != password)
            {
                return null;
            }
            return user;
        }
    }
}
